package com.itwlj.controller.admin;

import com.itwlj.constant.TypeConstant;
import com.itwlj.dto.PasswordUpdateDTO;
import com.itwlj.dto.UserLoginDTO;
import com.itwlj.result.Result;
import com.itwlj.service.UserService;
import com.itwlj.vo.UserLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 管理员
 */
@RestController
@RequestMapping("admin")
@Api(tags = "管理员相关接口")
@Slf4j
public class AdminController {

    @Autowired
    private UserService userService;

    /**
     * 登录
     *
     * @param userLoginDTO
     * @return
     */
    @PostMapping("/login")
    @ApiOperation("管理员登录")
    public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO) {
        log.info("管理员登录：{}", userLoginDTO);
        userLoginDTO.setType(TypeConstant.ADMIN);
        UserLoginVO userLoginVO = userService.login(userLoginDTO);
        return Result.success(userLoginVO);
    }

    /**
     * 修改密码
     *
     * @param passwordUpdateDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改密码")
    public Result<String> update(@RequestBody PasswordUpdateDTO passwordUpdateDTO) {
        log.info("修改密码：{}", passwordUpdateDTO);
        userService.updatePassword(passwordUpdateDTO);
        return Result.success();
    }
}
